package lol.oxguy3.android.mcmc;

import android.os.Bundle;
import android.preference.*;

public class SettingsActivity extends PreferenceActivity implements Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener {
	
	EditTextPreference prefConnTimeoutLimit;
	CheckBoxPreference prefConnUseData, prefConnIdentifyAsMcmc;
	ListPreference prefDispCapitalization, prefDispScreenOrientation, prefDispServerListSubtitles;
	Preference prefAcctLogOut, prefAcctNewSession;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		/** pull the preferences XML file */
		addPreferencesFromResource(R.xml.settings);
		
		
		/** initiating all the Preference variables */
		prefConnTimeoutLimit = (EditTextPreference) findPreference("conn_timeoutLimit");
		prefConnUseData = (CheckBoxPreference) findPreference("conn_useData");
		prefConnIdentifyAsMcmc = (CheckBoxPreference) findPreference("conn_identifyAsMcmc");
		
		prefDispCapitalization = (ListPreference) findPreference("disp_capitalization");
		prefDispScreenOrientation = (ListPreference) findPreference("disp_screenOrientation");
		prefDispServerListSubtitles = (ListPreference) findPreference("disp_serverListSubtitles");
		
		prefAcctLogOut = findPreference("acct_logOut");
		prefAcctNewSession = findPreference("acct_newSession");
		
		
		
		/** setting the defaults for the ListPreferences */
		if (prefDispCapitalization.getValue() == null) {
			prefDispCapitalization.setValueIndex(prefDispCapitalization.findIndexOfValue("sent"));
		}
		if (prefDispScreenOrientation.getValue() == null) {
			prefDispScreenOrientation.setValueIndex(prefDispScreenOrientation.findIndexOfValue("auto"));
		}
		if (prefDispServerListSubtitles.getValue() == null) {
			prefDispServerListSubtitles.setValueIndex(prefDispServerListSubtitles.findIndexOfValue("motd"));
		}
		
		
	}

	public boolean onPreferenceClick(Preference preference) {
		if (preference.equals(prefAcctLogOut)) {
			//TODO Set session ID to blank, create intent to jump to login screen
			return true;
		} else if (preference.equals(prefAcctNewSession)) {
			//TODO Re-authenticate with minecraft.net and store new session ID
			return true;
		} 
		return false;
	}

	public boolean onPreferenceChange(Preference preference, Object newValue) {
		if (preference.equals(prefConnTimeoutLimit)) {
			
		} else if (preference.equals(prefConnUseData)) {
			
		} else if (preference.equals(prefConnIdentifyAsMcmc)) {
			
		} else if (preference.equals(prefDispCapitalization)) {
			
		} else if (preference.equals(prefDispScreenOrientation)) {
			
		} else if (preference.equals(prefDispServerListSubtitles)) {
			
		} /*else if others??? */
		return false;
	}
}
